const http = require("http")
const fs = require("fs")
const path = require("path")
const serve = http.createServer()

// 绑定请求事件
serve.on('request', (req, res) => {
  let fpath = path.join(__dirname, '/clock', req.url)
  if (req.url === '/')
    fpath = path.join(__dirname, '/clock', 'index.html')
  // 读取文件
  fs.readFile(fpath, 'utf8',(err, data) => {
    if (err) {
      res.end('<h1>404 Not Found</h1>')
    }
    res.end(data)
  })
})

serve.listen(8080, () => {
  console.log('running')
})
